<template>
	<view class="page">
		<!-- 顶部菜单 -->
		<view class="topHeader" :style="'height:' + touHeight +'px;'">
			<view class="fanhuiUp" @tap="toFanhuiUp"></view>
		</view>
		<view class="page_content">
			<image :src="URL+'/JD_wx_img/sign_in_bg.png'" mode="widthFix" class="img_bg"></image>
			<view class="sign_xinxi">
				<image :src="URL+'/JD_wx_img/sign_logo.png'" mode="widthFix"></image>
				<view class="text">轻松找兼职</view>
			</view>
			<view class="sign_bottom">
				<button type="primary" class="form_btn" open-type="getUserInfo" @getuserinfo="getuserinfo" hover-class="btn-hover">微信授权登录</button>
				<view class="xieyi_xinxi">登录即表示同意<view class="xieyi" @tap="toXieyi">《用户协议》</view></view>
				<view class="sign_footer">© 2020 恒之森</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				//域名拼接
				URL: app.globalData.URL,
				touHeight: 0
			}
		},
		onLoad(options){
			var that = this;
			//自定义头部高度
			app.customNav()
			that.touHeight = app.touHeight + 5//搜索栏距离顶部高度
			
			//调用登录状态
			that.getuserinfo()
		},
		methods: {
			//登录账号
			getuserinfo(e){
				var that = this;
				uni.login({
					success: function (res){
						//拿到code
						var code = res.code
						uni.getUserInfo({
							lang:"zh_CN",
							success: function (res){ 
								// 把登录状态存在缓存
								uni.setStorageSync('userinfo', res.userInfo);
								uni.request({
									url: app.globalData.URL + '/api/v1/User/login?code='+code+'&nickname='+res.userInfo.nickName+'&avatar='+res.userInfo.avatarUrl,
									method: "get",
									success: function (res) {
										uni.setStorageSync('token', res.data.data.token);
										uni.setStorageSync('login', res.data.data);
										uni.setStorageSync('age', res.data.data.age);
										wx.showModal({
											title: '提示',
											content: '您已登录成功',
											showCancel: false,
											confirmColor:'#E85426',
											success (res) {
												if (res.confirm) {
													wx.navigateBack({
													    delta: 1
													})
												}
											}
										})		
									}
								})
							},
							fail: function (res) {
								console.log('未登录')
							}
					    })
					},
				})
			},
			
			//跳转到协议
			toXieyi:function(){
				uni.navigateTo({
				    url: 'user_text/user_text',
				});
			},
			
			//返回上一级
			toFanhuiUp:function(){
				uni.navigateBack({
				    delta: 1
				})
			},
		}
	}
</script>

<style>
	page{
		background: #fff;
		width: 100%;
		height: 100%;
	}
	.page{
		width: 100%;
		height: 100%;
	}
	.page_content{
		padding: 0px;
		width: 100%;
		height: 100%;
	}
	.topHeader .fanhuiUp{
		background: url(https://jianzhi.huanyuweizhi.com/JD_wx_img/header_fanhui_img02.png) bottom 10rpx center no-repeat;
		background-size: 24rpx 48rpx !important;
	}
	.page_content .img_bg{
		position: absolute;
		left: 0px;
		top: 0px;
		width: 100%;
	}
	.sign_xinxi{
		width: 240rpx;
		position: absolute;
		left: 50%;
		margin-left: -120rpx;
		z-index: 5;
		top:400rpx;
	}
	.sign_xinxi image{
		display: block;
		width: 100%;
	}
	.sign_xinxi .text{
		text-align: center;
		font-size: 34rpx;
		color: #333333;
		margin-top: 20rpx;
	}
	.sign_bottom{
		position: absolute;
		bottom: 0px;
		left: 0px;
		right: 0px;
		z-index: 5;
		margin: 0px 30rpx;
	}
	.form_btn{
		background: #E85426;
		border-radius: 50rpx;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 34rpx;
		color: #fff;
		text-align: center;
		background: #E85426!important;
		padding: 0px!important;
		width: 100%!important;
	}
	.xieyi_xinxi{
		color: #888888;
		font-size: 24rpx;
		text-align: center;
		margin-top: 32rpx;
	}
	.xieyi_xinxi .xieyi{
		color: #E85426;
		display: inline-block;
	}
	.sign_footer{
		font-size: 24rpx;
		text-align: center;
		color: #888888;
		margin-top: 50rpx;
		margin-bottom: 100rpx;
	}
</style>
